package jp.co.jalinfotec.sxt.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.co.jalinfotec.sxt.dto.UserDto;
import jp.co.jalinfotec.sxt.form.EntryUserActionForm;
import jp.co.jalinfotec.sxt.service.UserService;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * register user
 */
public class EntryUserAction extends Action{

	/** User logic */
	@Autowired
	private UserService userService = null;
	
	/**
	 * Register user
	 * @param map Mapping information of URL and action
	 * @param form Request parameters
	 * @param request Request object
	 * @param response Response Object
	 */
	@Override
	public ActionForward execute(
			ActionMapping map, ActionForm form, 
			HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		EntryUserActionForm userForm = (EntryUserActionForm)form;
		
		UserDto dto =
				new UserDto(userForm.getUserId(), userForm.getUserName(), userForm.getPassword());

		// register user
		this.userService.store(dto);
		return map.findForward("success");
	}
}
